//
//  ResultModel.swift
//  TODOApp
//
//  Created by chenyh on 2018/5/24.
//  Copyright © 2018年 chenyh. All rights reserved.
//

import Foundation

public struct BaseModel {
    var message: String = ""
    var status: Int = 0
    //如果data类型能确定为[:] 或 [] 其中一个就 不用 Decodable这个可以直接用HandyJson来解析
    var result: Any?
}

public protocol Decodable {
    static func parse(any: Any) -> Self?
}


extension BaseModel {
    func mapModel<T: Decodable>(_ type: T.Type) -> T? {
        guard self.status == 1  else { return nil }
        guard let tdata = self.result  else { return nil }
        guard let parsermodel = type.parse(any: tdata) else { return nil}
        return  parsermodel
    }

}
